import java.util.concurrent.Semaphore;

public class Demo5 {
    public static void main(String[] args) throws InterruptedException {
        //参数为可用资源的个数，计数器的初始值
        Semaphore semaphore = new Semaphore(3);

        semaphore.acquire();
        System.out.println("申请一个资源1");
        semaphore.acquire();
        System.out.println("申请一个资源2");
        semaphore.acquire();
        System.out.println("申请一个资源3");
        semaphore.release();
        System.out.println("释放一个资源");
        semaphore.acquire();
        System.out.println("申请一个资源4");
    }
}
